
const state = {
  dict: {},
};

const mutations = {
  SET_DICT: (state, { name,value }) => {
    state[name] = value
  },
};
const actions = {
  // 新增字典
  async adddict({ state,commit }, dicinfo) {
    const { diccode } = dicinfo;
    if (state[diccode]) {
      return Promise.resolve(state[diccode]);
    }
    return new Promise((resolve,reject) => {
      this._vm.$api.utils.sysDictionary({
        dictCode: diccode
      }).then(val => {
        commit("SET_DICT", { name: diccode ,value: val });
        resolve(val);
      });
    })
    // const val = await this._vm.$api.utils.sysDictionary({
    //   dictCode: diccode
    // })
    // commit("SET_DICT", { name: diccode ,value: val });
    // return Promise.resolve(val);
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
